package com.ouwen.smartpay.service.chain.slots.log;

import com.ouwen.smartpay.openapi.order.ServiceOrder;
import com.ouwen.smartpay.openapi.result.ServiceResult;
import com.ouwen.smartpay.service.chain.context.Context;
import com.ouwen.smartpay.service.chain.slotchain.AbstractLinkedProcessorSlot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @author <a href="http://youngitman.tech">青年IT男</a>
 * @version v1.0.0
 * @className LogSlot
 * @description 统一日志记录
 * @JunitTest: {@link  }
 * @date 2020-04-22 11:23
 **/
public class LogSlot extends AbstractLinkedProcessorSlot<ServiceOrder> {

    Logger logger = LoggerFactory.getLogger(LogSlot.class);

    @Override
    public void entry(Context context, ServiceOrder serviceOrder, Object... args) throws Throwable {

        logger.info("Openapi统一入参:{}", serviceOrder);

        fireEntry(context, serviceOrder, args);

    }

    @Override
    public void exit(Context context, Object... args) {

        Object[] objects = (Object[]) args[1];

        Object object = objects[0];

        if (object != null && object instanceof ServiceResult){

            ServiceResult result = (ServiceResult) object;

            logger.info("Openapi统一出参:{}", result);
        }

        fireExit(context, args);

    }
}
